#include "utilities.h"

void* eventDispatcher(void *ptr)
{
	while(!dieChild)
	{
		pthread_mutex_lock(&eventQueueMutex);
		if(!eventQueue.empty())
		{
			listBuffStruct eventReq = eventQueue.front();
			eventQueue.pop_front();
			pthread_mutex_unlock(&eventQueueMutex);
			msg_header msgRespHdr;
			fillMsgHdrStructure(msgRespHdr, eventReq.listBuff);
			if((uint8_t)msgRespHdr.msgtype == 0xF8)
			{
				continue;
			}
			//For JOIN Request or Response
			joinProcessing(msgRespHdr, eventReq);
			
			//For STATUS Request or Response
			statusProcessing(msgRespHdr, eventReq);
			
			//For Notify Request Message
			notifyProcessing(msgRespHdr, eventReq);
		}
		else
		{
			pthread_mutex_unlock(&eventQueueMutex);
		}
		usleep(1);
	}
	pthread_exit(NULL);
}
